#include <stdlib.h>
#define IsDigit(a) (a <= '9' && a >= '0')
#define ToDigit(a) (a - '0')
#include <stdint.h>
#include "MyAtoi.h"
int myAtoi(char *s)
{
    if (s == NULL)
        return 0;
    long tmp = 0;
    int negative = 0;
    char *ptr = s;
    while (*ptr != '\0' && *ptr == ' ')
        ptr++;
    if (*ptr == '-')
    {
        negative = 1;
        ptr++;
    }
    else if (*ptr == '+')
        ptr++;
    while (IsDigit(*ptr))
    {
        if (negative)
        {
            tmp = 10 * tmp - ToDigit(*ptr);
            if (tmp < INT32_MIN)
                return INT32_MIN;
        }
        else
        {
            tmp = 10 * tmp + ToDigit(*ptr);
            if (tmp > INT32_MAX)
                return INT32_MAX;
        }
        ptr++;
    }

    return tmp;
}